(module date mzscheme
  (provide week-of?
           get-date
           run-date->ordinal-week
           get-year
           date->run-date
           time->run-time)
  
  (require (only (lib "19.ss" "srfi")
                 current-date
                 date->string
                 date-week-number
                 string->date)
           (rename (lib "19.ss" "srfi") srfi-date-month date-month)
           (rename (lib "19.ss" "srfi") srfi-date-day date-day) 
           (rename (lib "19.ss" "srfi") srfi-date-year date-year)
           (rename (lib "19.ss" "srfi") srfi-date-hour date-hour) 
           (rename (lib "19.ss" "srfi") srfi-date-minute date-minute) 
           (rename (lib "19.ss" "srfi") srfi-date-second date-second)
           (lib "string.ss")
           "string.ss")
  
  (define (run-date->date run-date)
    "run-date->date takes a run-date and returns an SRFI 19 date."
    (string->date (string-append (buffer-number (car run-date))
                                 (buffer-number (cadr run-date))
                                 (buffer-number (caddr run-date)))
                  "~m~d~Y"))
  
  (define (date->run-date str-date)
    "date->run-date takes a date in M/D/YYYY format and returns a run-date"
    (map string->number (regexp-split "/" str-date)))
  
  (define (time->run-time str-time)
    "time->run-time takes a time in h:m:s format and returns a run-time"
    (map string->number (regexp-split ":" str-time)))
  
  (define (week-of? start-date quest-date)
    "week-of? returns #t if question-date is in the same ordinal week of the year and the same year of start-date or #f otherwise"
    (let ((start (run-date->date start-date))
          (quest (run-date->date quest-date)))
      (and (= (caddr start-date) ; Years are equal
              (caddr quest-date))
           (= (date-week-number start 0)
              (date-week-number quest 0)))))
  
  (define (run-date->ordinal-week run-date)
    "run-date->ordinal-week returns the ordinal week of the year this run-date occurred in"
    (date-week-number (run-date->date run-date) 0))
  
  (define (get-date)
    "get-date returns a list of three strings: the month, day, and year of today's date."
    (let ((today (date->string (current-date)
                               "~Y-~m-~d")))
      (list (substring today 5 7)
            (substring today 8 10)
            (substring today 0 4))))
  
  (define (get-year)
    (string->number (date->string (current-date) "~Y"))))